<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="/static/jQuery-1.11/jquery-1.11.3.min.js"></script>
    <script>
        $(function () {
            $("#newPassword").blur(function () {
                var newPassword = $(this).val();
                var param = "newPassword=" + newPassword;
                // 检查密码
                $.get('/user/checkNewPassword',param,function (data) {
                    if (data.success) {  // 合理
                        $("#button").attr('disabled', false);
                        $("#p1").html('');  //清除提示信息
                    }else { // 不合理
                        $("#p1").html(data.msg).css('color','red');
                        $("#button").attr('disabled', true); //禁止提交
                    }
                })
            });

            $("#button").click(function () {
                var username = $("#newPassword").val();
                var password = $("#surePassword").val();
                var param = "newPassword=" + username + "&surePassword=" + password;
                $.post("/user/updateKey", param, function (data) {
                    if (data.success){ // 修改成功
                        location.href = "login2.html";
                    }else { // 失败
                        $("#p2").html(data.msg).css('color', 'red');
                    }
                })

            })
        });
    </script>
</head>
<body>
<h4>修改密码</h4>

    新密码：<input type="password" name="newPassword" id="newPassword"><span id="p1"></span><br/>
    确认密码：<input type="password" name="surePassword" id="surePassword"><span id="p2"></span><br/>
    <input id="button" type="button" value="确认修改"/>


</body>
